home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / Container / Sources / Commands.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  27.4 KB  |  851 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Commands.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Container.hpp"
  11.  
  12. #ifndef COMMANDS_H
  13. #include "Commands.h"
  14. #endif
  15.  
  16. #ifndef DEFINES_K
  17. #include "Defines.k"
  18. #endif
  19.  
  20. #ifndef PART_H
  21. #include "Part.h"
  22. #endif
  23.  
  24. #ifndef CONTENT_H
  25. #include "Content.h"
  26. #endif
  27.  
  28. #ifndef FRAME_H
  29. #include "Frame.h"
  30. #endif
  31.  
  32. #ifndef SELECT_H
  33. #include "Select.h"
  34. #endif
  35.  
  36. #ifndef PROXY_H
  37. #include "Proxy.h"
  38. #endif
  39.  
  40. #ifndef FWFRAME_H
  41. #include "FWFrame.h"
  42. #endif
  43.  
  44. #ifndef FWPRESEN_H
  45. #include "FWPresen.h"
  46. #endif
  47.  
  48. #ifndef FWFCTCLP_H
  49. #include "FWFctClp.h"
  50. #endif
  51.  
  52. #ifndef FWMEMMGR_H
  53. #include "FWMemMgr.h"
  54. #endif
  55.  
  56. #ifndef FWSOMENV_H
  57. #include "FWSOMEnv.h"
  58. #endif
  59.  
  60. // ----- OpenDoc Includes -----
  61.  
  62. #ifndef SOM_Module_OpenDoc_Commands_defined
  63. #include <CmdDefs.xh>
  64. #endif
  65.  
  66. #ifndef SOM_ODShape_xh
  67. #include <Shape.xh>
  68. #endif
  69.  
  70. //========================================================================================
  71. // Runtime Information
  72. //========================================================================================
  73.  
  74. #ifdef FW_BUILD_MAC
  75. #pragma segment odfcontainer
  76. #endif
  77.  
  78. FW_DEFINE_AUTO(CClipboardCommand)
  79. FW_DEFINE_AUTO(CDragCommand)
  80. FW_DEFINE_AUTO(CDropCommand)
  81. FW_DEFINE_AUTO(CInsertCommand)
  82. FW_DEFINE_AUTO(CResizeCommand)
  83. FW_DEFINE_AUTO(CViewAsCommand)
  84. FW_DEFINE_AUTO(CSetBackgroundColorCommand)
  85.  
  86. //========================================================================================
  87. // CClipboardCommand
  88. //========================================================================================
  89.  
  90. //----------------------------------------------------------------------------------------
  91. //    CClipboardCommand constructor
  92. //----------------------------------------------------------------------------------------
  93.  
  94. CClipboardCommand::CClipboardCommand(Environment* ev, 
  95.                                      ODCommandID commandID,
  96.                                      CContainerPart* part, 
  97.                                      CContainerFrame* frame, 
  98.                                      CContainerSelection* selection,
  99.                                      FW_Boolean canUndo) :
  100.     FW_CClipboardCommand(ev, commandID, frame, canUndo),
  101.         fContainerPart(part),
  102.         fContainerSelection(selection),
  103.         fUndoContent(NULL)
  104. {
  105.     FW_END_CONSTRUCTOR
  106. }
  107.  
  108. //----------------------------------------------------------------------------------------
  109. //    CClipboardCommand destructor
  110. //----------------------------------------------------------------------------------------
  111.  
  112. CClipboardCommand::~CClipboardCommand()
  113. {
  114.     FW_START_DESTRUCTOR
  115.  
  116.     delete fUndoContent;
  117. }
  118.  
  119. //----------------------------------------------------------------------------------------
  120. //    CClipboardCommand::SaveUndoState
  121. //----------------------------------------------------------------------------------------
  122. void CClipboardCommand::SaveUndoState(Environment* ev)    // Override
  123. {
  124.     ODCommandID commandID = GetCommandID(ev);
  125.     
  126.     if (commandID == kODCommandCut || commandID == kODCommandClear)
  127.     {
  128.         FW_ASSERT(fUndoContent == NULL);
  129.         fUndoContent = FW_NEW(CUndoContent, (ev, fContainerSelection));
  130.     }
  131. }
  132.  
  133. //----------------------------------------------------------------------------------------
  134. //    CClipboardCommand::SaveRedoState
  135. //----------------------------------------------------------------------------------------
  136. void CClipboardCommand::SaveRedoState(Environment* ev)    // Override
  137. {
  138.     if (GetCommandID(ev) == kODCommandPaste)
  139.     {
  140.         FW_ASSERT(fUndoContent == NULL);
  141.         fUndoContent = FW_NEW(CUndoContent, (ev, fContainerSelection));
  142.     }    
  143. }
  144.  
  145. //----------------------------------------------------------------------------------------
  146. //    CClipboardCommand::FreeUndoState
  147. //----------------------------------------------------------------------------------------
  148. void CClipboardCommand::FreeUndoState(Environment* ev)    // Override
  149. {
  150.     ODCommandID commandID = GetCommandID(ev);
  151.     
  152.     if (commandID == kODCommandPaste)
  153.         fUndoContent->CommitPasteDone(ev);
  154. }
  155.  
  156. //----------------------------------------------------------------------------------------
  157. //    CClipboardCommand::UndoIt
  158. //----------------------------------------------------------------------------------------
  159. void CClipboardCommand::UndoIt(Environment* ev)    // Override
  160. {
  161.     FW_CClipboardCommand::UndoIt(ev);    // call inherited
  162.  
  163.     switch (GetCommandID(ev))
  164.     {
  165.         case kODCommandCut:
  166.         case kODCommandClear:
  167.             fUndoContent->RestoreProxySelection(ev);
  168.             break;
  169.  
  170.         case kODCommandPaste:
  171.             fUndoContent->RemoveProxySelection(ev);
  172.             break;
  173.     }    
  174. }
  175.  
  176. //----------------------------------------------------------------------------------------
  177. //    CClipboardCommand::RedoIt
  178. //----------------------------------------------------------------------------------------
  179. void CClipboardCommand::RedoIt(Environment* ev)    // Override
  180. {
  181.     FW_CClipboardCommand::RedoIt(ev);    // call inherited
  182.  
  183.     switch (GetCommandID(ev))
  184.     {
  185.         case kODCommandCut:
  186.         case kODCommandClear:
  187.             fUndoContent->RemoveProxySelection(ev);
  188.             break;
  189.  
  190.         case kODCommandPaste:
  191.             fUndoContent->RestoreProxySelection(ev);
  192.             break;
  193.     }    
  194. }
  195.  
  196. //----------------------------------------------------------------------------------------
  197. //    CClipboardCommand::PreCommand
  198. //----------------------------------------------------------------------------------------
  199.  
  200. void CClipboardCommand::PreCommand(Environment* ev)
  201. {
  202.     if (GetCommandID(ev) == kODCommandPaste)
  203.         fContainerSelection->CloseSelection(ev);
  204. }
  205.  
  206. //----------------------------------------------------------------------------------------
  207. //    CClipboardCommand::CommandDone
  208. //----------------------------------------------------------------------------------------
  209.  
  210. void CClipboardCommand::CommandDone(Environment* ev)
  211. {
  212.     if (GetCommandID(ev) == kODCommandPaste)
  213.         fContainerSelection->CenterSelection(ev, GetContextFrame(ev));
  214. }
  215.  
  216. //========================================================================================
  217. // class CDragCommand
  218. //========================================================================================
  219.  
  220. //----------------------------------------------------------------------------------------
  221. //    CDragCommand constructor
  222. //----------------------------------------------------------------------------------------
  223. CDragCommand::CDragCommand(Environment* ev,
  224.                            CContainerPart* part,
  225.                            FW_CFrame* frame,
  226.                            CContainerSelection* selection,
  227.                            FW_Boolean canUndo)
  228.     : FW_CDragCommand(ev, frame, canUndo),
  229.         fContainerPart(part),
  230.         fContainerSelection(selection),
  231.         fDraggedContent(NULL)
  232. {
  233.     FW_END_CONSTRUCTOR
  234. }
  235.  
  236. //----------------------------------------------------------------------------------------
  237. //    CDragCommand destructor
  238. //----------------------------------------------------------------------------------------
  239.  
  240. CDragCommand::~CDragCommand()
  241. {
  242.     FW_START_DESTRUCTOR
  243.  
  244.     delete fDraggedContent;        // Will call remove all if necessary
  245.     fDraggedContent = NULL;
  246. }
  247.  
  248. //----------------------------------------------------------------------------------------
  249. //    CDragCommand::SaveUndoState
  250. //----------------------------------------------------------------------------------------
  251.  
  252. void CDragCommand::SaveUndoState(Environment* ev)    // Override
  253. {
  254.     FW_ASSERT(fDraggedContent == NULL);    
  255.     fDraggedContent = FW_NEW(CUndoContent, (ev, fContainerSelection));
  256. }
  257.  
  258. //----------------------------------------------------------------------------------------
  259. //    CDragCommand::UndoIt
  260. //----------------------------------------------------------------------------------------
  261.  
  262. void CDragCommand::UndoIt(Environment* ev)    // Override
  263. {
  264.     // ----- Add the dragged proxies back into the part
  265.     CContentProxyIterator ite(fDraggedContent);
  266.     for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  267.     {
  268.         fContainerPart->AttachProxy(ev, proxy);
  269.     }
  270.  
  271.     // ----- Add the saved proxies to the selection
  272.     fContainerSelection->SelectContent(ev, fDraggedContent);
  273.     
  274.     // ----- Invalidate 
  275.     GetPresentation(ev)->Invalidate(ev, fContainerSelection->GetUpdateShape(ev));
  276. }
  277.  
  278. //----------------------------------------------------------------------------------------
  279. //    CDragCommand::RedoIt
  280. //----------------------------------------------------------------------------------------
  281.  
  282. void CDragCommand::RedoIt(Environment* ev)    // Override
  283. {
  284.     // Select saved proxies
  285.     fContainerSelection->SelectContent(ev, fDraggedContent);
  286.  
  287.     fContainerSelection->ClearSelection(ev); // clear them, again
  288. }
  289.  
  290. //========================================================================================
  291. // class CDropCommand
  292. //========================================================================================
  293.  
  294. //----------------------------------------------------------------------------------------
  295. //    CDropCommand constructor
  296. //----------------------------------------------------------------------------------------
  297. CDropCommand::CDropCommand(Environment* ev,
  298.                            CContainerPart* part,
  299.                            FW_CFrame* frame,
  300.                            ODDragItemIterator* dropInfo, 
  301.                            ODFacet* facet, 
  302.                            const FW_CPoint& dropPoint,
  303.                            FW_Boolean canUndo)
  304.     : FW_CDropCommand(ev, frame, dropInfo, facet, dropPoint, canUndo),
  305.         fContainerPart(part),
  306.         fDropDelta(FW_kZeroPoint),
  307.         fDroppedContent(NULL),
  308.         fContainerSelection((CContainerSelection*)frame->GetPresentation(ev)->GetSelection(ev))
  309. {
  310.     FW_END_CONSTRUCTOR
  311. }
  312.  
  313. //----------------------------------------------------------------------------------------
  314. //    CDropCommand destructor
  315. //----------------------------------------------------------------------------------------
  316.  
  317. CDropCommand::~CDropCommand()
  318. {
  319.     FW_START_DESTRUCTOR
  320.  
  321.     delete fDroppedContent;
  322. }
  323.  
  324. //----------------------------------------------------------------------------------------
  325. //    CDropCommand::DoDrop
  326. //----------------------------------------------------------------------------------------
  327. FW_Boolean CDropCommand::DoDrop(Environment* ev, 
  328.                                 ODStorageUnit* dropSU, 
  329.                                 const FW_CPoint& mouseDownOffset, 
  330.                                 const FW_CPoint& dropPoint,
  331.                                 FW_Boolean isDropMove,
  332.                                 short itemNumber)
  333. {
  334.     if (itemNumber == 1)
  335.         fContainerSelection->CloseSelection(ev);
  336.     
  337.     FW_Boolean result = FW_CDropCommand::DoDrop(ev, dropSU, mouseDownOffset, dropPoint, isDropMove, itemNumber);
  338.     
  339.     if (result)
  340.     {    
  341.         fContainerSelection->CalcCache(ev);
  342.         
  343.         FW_CPoint newPosition(dropPoint.x - mouseDownOffset.x, dropPoint.y - mouseDownOffset.y);
  344.         
  345.         FW_CRect box = fContainerSelection->GetDragRect(ev);
  346.  
  347.         fContainerSelection->OffsetSelection(ev, newPosition.x - box.left, newPosition.y - box.top);
  348.         
  349.         ODShape* updateShape = fContainerSelection->GetUpdateShape(ev);
  350.         
  351.         // ----- Calculate clip -----
  352.         FW_CFacetClipper facetClipper;
  353.         facetClipper.Clip(ev, fContainerSelection->GetPresentation(ev), updateShape);    
  354.  
  355.         // ----- Invalidate -----
  356.         GetPresentation(ev)->Invalidate(ev, updateShape);
  357.         
  358.         // ----- If I am not the active part I should not have a selection -----
  359.         if (!fContainerPart->HasSelectionFocus(ev))
  360.             fContainerSelection->CloseSelection(ev);
  361.     }
  362.     
  363.     return result;
  364. }
  365.  
  366. //----------------------------------------------------------------------------------------
  367. //    CDropCommand::DoDroppedInSameFrame
  368. //----------------------------------------------------------------------------------------
  369. FW_Boolean CDropCommand::DoDroppedInSameFrame(Environment* ev, 
  370.                                               ODStorageUnit* dropSU, 
  371.                                               const FW_CPoint& mouseDownOffset,
  372.                                               const FW_CPoint& dropPoint)
  373. {
  374.     FW_UNUSED(dropSU);
  375.     
  376.     FW_CPoint newPosition(dropPoint.x - mouseDownOffset.x, dropPoint.y - mouseDownOffset.y);
  377.             
  378.     FW_CRect box = fContainerSelection->GetDragRect(ev);
  379.  
  380.     fDropDelta = newPosition - box.TopLeft();
  381.     this->OffsetSelection(ev, fDropDelta);
  382.  
  383.     return TRUE;
  384. }
  385.  
  386. //----------------------------------------------------------------------------------------
  387. //    CDropCommand::SaveRedoState
  388. //----------------------------------------------------------------------------------------
  389.  
  390. void CDropCommand::SaveRedoState(Environment* ev)    // Override
  391. {
  392.     // Save proxies that were just dropped
  393.     FW_ASSERT(fDroppedContent == NULL);
  394.     fDroppedContent = FW_NEW(CUndoContent, (ev, fContainerSelection));
  395. }
  396.  
  397. //----------------------------------------------------------------------------------------
  398. //    CDropCommand::UndoIt
  399. //----------------------------------------------------------------------------------------
  400. void CDropCommand::UndoIt(Environment* ev)    // Override
  401. {
  402.     if (this->IsDragMoveInSameFrame(ev))    // it's a drag-move
  403.     {
  404.         // select dropped proxies and move them back to the original position
  405.         fContainerSelection->SelectContent(ev, fDroppedContent);
  406.         this->OffsetSelection(ev, -fDropDelta);
  407.     }
  408.     else
  409.     {
  410.         // select dropped proxies and remove them from the document
  411.         fContainerSelection->SelectContent(ev, fDroppedContent);
  412.         fContainerSelection->ClearSelection(ev);
  413.     }
  414. }
  415.  
  416. //----------------------------------------------------------------------------------------
  417. //    CDropCommand::RedoIt
  418. //----------------------------------------------------------------------------------------
  419. void CDropCommand::RedoIt(Environment* ev)    // Override
  420. {
  421.     if (this->IsDragMoveInSameFrame(ev))    // it's a drag-move
  422.     {
  423.         // select dropped proxies and move them to new position
  424.         fContainerSelection->SelectContent(ev, fDroppedContent);
  425.         this->OffsetSelection(ev, fDropDelta);
  426.     }
  427.     else    // dropped proxies are copies
  428.     {
  429.         // add dropped proxies back into document
  430.         this->RestoreDroppedProxies(ev);
  431.         GetPresentation(ev)->Invalidate(ev, fContainerSelection->GetUpdateShape(ev));
  432.     }
  433. }
  434.  
  435. //----------------------------------------------------------------------------------------
  436. //    CDropCommand::RestoreDroppedProxies
  437. //----------------------------------------------------------------------------------------
  438.  
  439. void CDropCommand::RestoreDroppedProxies(Environment* ev)
  440. {
  441.     // Add the dropped proxies back into the part
  442.     CContentProxyIterator ite(fDroppedContent);
  443.     for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  444.     {
  445.         fContainerPart->AttachProxy(ev, proxy);
  446.     }
  447.  
  448.     // Add the saved proxies to the selection
  449.     fContainerSelection->SelectContent(ev, fDroppedContent);
  450. }
  451.  
  452. //----------------------------------------------------------------------------------------
  453. //    CDropCommand::OffsetSelection
  454. //----------------------------------------------------------------------------------------
  455.  
  456. void CDropCommand::OffsetSelection(Environment* ev, const FW_CPoint& delta)
  457. {
  458.     if (delta != FW_kZeroPoint)
  459.     {
  460.         GetPresentation(ev)->Invalidate(ev, fContainerSelection->GetUpdateShape(ev));
  461.         fContainerSelection->OffsetSelection(ev, delta.x, delta.y);
  462.         GetPresentation(ev)->Invalidate(ev, fContainerSelection->GetUpdateShape(ev));
  463.     }
  464. }
  465.  
  466. //----------------------------------------------------------------------------------------
  467. //    CDropCommand::FreeUndoState
  468. //----------------------------------------------------------------------------------------
  469. void CDropCommand::FreeUndoState(Environment* ev)    // Override
  470. {
  471.     if (fDroppedContent)
  472.         fDroppedContent->CommitPasteDone(ev);
  473. }
  474.  
  475. //========================================================================================
  476. // CInsertCommand
  477. //========================================================================================
  478.  
  479. //----------------------------------------------------------------------------------------
  480. //    CInsertCommand constructor
  481. //----------------------------------------------------------------------------------------
  482.  
  483. CInsertCommand::CInsertCommand(Environment* ev, 
  484.                                CContainerFrame* frame, 
  485.                                const FW_PFileSpecification& fileSpec, 
  486.                                CContainerSelection* selection,
  487.                                FW_Boolean canUndo) :
  488.     FW_CInsertCommand(ev, frame, fileSpec, canUndo),
  489.     fUndoContent(NULL),
  490.     fContainerSelection(selection)
  491. {
  492.     FW_END_CONSTRUCTOR
  493. }
  494.  
  495. //----------------------------------------------------------------------------------------
  496. //    CInsertCommand destructor
  497. //----------------------------------------------------------------------------------------
  498.  
  499. CInsertCommand::~CInsertCommand()
  500. {
  501.     FW_START_DESTRUCTOR
  502.  
  503.     delete fUndoContent;
  504. }
  505.  
  506. //----------------------------------------------------------------------------------------
  507. //    CInsertCommand::PreCommand
  508. //----------------------------------------------------------------------------------------
  509.  
  510. void CInsertCommand::PreCommand(Environment* ev)
  511. {
  512.     fContainerSelection->CloseSelection(ev);
  513. }
  514.  
  515. //----------------------------------------------------------------------------------------
  516. //    CInsertCommand::CommandDone
  517. //----------------------------------------------------------------------------------------
  518.  
  519. void CInsertCommand::CommandDone(Environment* ev)
  520. {
  521.     fContainerSelection->CenterSelection(ev, GetContextFrame(ev));
  522. }
  523.  
  524. //----------------------------------------------------------------------------------------
  525. //    CInsertCommand::SaveRedoState
  526. //----------------------------------------------------------------------------------------
  527.  
  528. void CInsertCommand::SaveRedoState(Environment* ev)
  529. {
  530.     FW_ASSERT(fUndoContent == NULL);
  531.     fUndoContent = FW_NEW(CUndoContent, (ev, fContainerSelection));
  532. }
  533.  
  534. //----------------------------------------------------------------------------------------
  535. //    CInsertCommand::UndoIt
  536. //----------------------------------------------------------------------------------------
  537.  
  538. void CInsertCommand::UndoIt(Environment* ev)
  539. {
  540.     FW_CInsertCommand::UndoIt(ev);
  541.     fUndoContent->RemoveProxySelection(ev);
  542. }
  543.  
  544. //----------------------------------------------------------------------------------------
  545. //    CInsertCommand::RedoIt
  546. //----------------------------------------------------------------------------------------
  547.  
  548. void CInsertCommand::RedoIt(Environment* ev)
  549. {
  550.     FW_CInsertCommand::RedoIt(ev);
  551.     fUndoContent->RestoreProxySelection(ev);
  552. }
  553.  
  554. //========================================================================================
  555. // CResizeCommand
  556. //========================================================================================
  557.  
  558. //----------------------------------------------------------------------------------------
  559. //    CResizeCommand constructor
  560. //----------------------------------------------------------------------------------------
  561. CResizeCommand::CResizeCommand(Environment* ev, 
  562.                                          CContainerPart* part, 
  563.                                          FW_CFrame* frame,
  564.                                          CContainerSelection* selection,
  565.                                          const FW_CRect& srcRect,
  566.                                          const FW_CRect& dstRect) 
  567. :    FW_CCommand(ev, cResizeCommand, frame, FW_kCanUndo),
  568.     fContainerPart(part),
  569.     fContainerSelection(selection),
  570.     fSourceRect(srcRect),
  571.     fDestRect(dstRect),
  572.     fUpdateShape(NULL),
  573.     fChangedContent(NULL)
  574. {
  575.     SetMenuStringsFromResource(ev, kUndoStrings, kUndoResizeMsg, kRedoResizeMsg);
  576.     FW_END_CONSTRUCTOR    
  577. }
  578.  
  579. //----------------------------------------------------------------------------------------
  580. //    CResizeCommand destructor
  581. //----------------------------------------------------------------------------------------
  582. CResizeCommand::~CResizeCommand()
  583. {
  584.     FW_START_DESTRUCTOR
  585.     delete fChangedContent;
  586.     
  587.     if (fUpdateShape)
  588.     {
  589.         FW_SOMEnvironment ev;
  590.         fUpdateShape->Release(ev);
  591.     }
  592.     fUpdateShape = NULL;
  593. }
  594.  
  595. //----------------------------------------------------------------------------------------
  596. //    CResizeCommand::DoIt
  597. //----------------------------------------------------------------------------------------
  598. void CResizeCommand::DoIt(Environment* ev)    // Override
  599. {
  600.     // Copy selected proxy pointers to our content object
  601.     FW_ASSERT(fChangedContent == NULL);
  602.     fChangedContent = FW_NEW(CBaseContent, (ev, fContainerSelection->GetSelectionContent(ev)));
  603.  
  604.     FW_ASSERT(fUpdateShape == NULL);
  605.     fUpdateShape = fChangedContent->CalcUpdateShape(ev);
  606.  
  607.     this->ResizeProxies(ev, fSourceRect, fDestRect);
  608.  
  609.     {
  610.         FW_CAcquiredODShape tempShape = fChangedContent->CalcUpdateShape(ev);
  611.         fUpdateShape->Union(ev, tempShape);
  612.     }
  613.  
  614.     this->Redraw(ev, kODDone);
  615. }
  616.  
  617. //----------------------------------------------------------------------------------------
  618. //    CResizeCommand::UndoIt
  619. //----------------------------------------------------------------------------------------
  620. void CResizeCommand::UndoIt(Environment* ev)    // Override
  621. {
  622.     this->ResizeProxies(ev, fDestRect, fSourceRect);
  623.     this->Redraw(ev, kODUndone);
  624. }
  625.  
  626. //----------------------------------------------------------------------------------------
  627. //    CResizeCommand::RedoIt
  628. //----------------------------------------------------------------------------------------
  629. void CResizeCommand::RedoIt(Environment* ev)    // Override
  630. {
  631.     this->ResizeProxies(ev, fSourceRect, fDestRect);
  632.     this->Redraw(ev, kODRedone);
  633. }
  634.  
  635. //----------------------------------------------------------------------------------------
  636. //    CResizeCommand::ResizeProxies
  637. //----------------------------------------------------------------------------------------
  638. void CResizeCommand::ResizeProxies(Environment* ev, const FW_CRect& srcRect, const FW_CRect& dstRect)
  639. {
  640.     //--- Resize each proxy ---
  641.     CContentProxyIterator it(fChangedContent);
  642.     for (CProxy* proxy = it.First(); it.IsNotComplete(); proxy = it.Next())
  643.     {
  644.         proxy->ResizeProxy(ev, srcRect, dstRect);
  645.     }
  646. }
  647.  
  648. //----------------------------------------------------------------------------------------
  649. //    CResizeCommand::Redraw
  650. //----------------------------------------------------------------------------------------
  651. void CResizeCommand::Redraw(Environment* ev, ODDoneState doneState)
  652. {
  653. FW_UNUSED(doneState);
  654.     FW_CPresentation* presentation = fContainerPart->GetMainPresentation();
  655.     presentation->Invalidate(ev, fUpdateShape);
  656.     
  657.     FW_CFacetClipper facetClipper;
  658.     facetClipper.Clip(ev, presentation, fUpdateShape);
  659.  
  660.     // Select the resized proxies
  661.     fContainerSelection->SelectContent(ev, fChangedContent);
  662. }
  663.  
  664. //========================================================================================
  665. // CViewAsCommand
  666. //========================================================================================
  667.  
  668. //----------------------------------------------------------------------------------------
  669. //    CViewAsCommand constructor
  670. //----------------------------------------------------------------------------------------
  671. CViewAsCommand::CViewAsCommand(Environment* ev, 
  672.                                 CContainerPart* part,
  673.                                 FW_CFrame* frame,
  674.                                 CContainerSelection* selection,
  675.                                 ODTypeToken newViewAs) 
  676. :    FW_CCommand(ev, cViewAsCommand, frame, FW_kCanUndo),
  677.     fContainerPart(part),
  678.     fContainerSelection(selection),
  679.     fNewViewAs(newViewAs),
  680.     fOldViewAs(NULL),
  681.     fChangedContent(NULL),
  682.     fUpdateShape(NULL)
  683. {
  684.     SetMenuStringsFromResource(ev, kUndoStrings, kUndoEmbedAsMsg, kRedoEmbedAsMsg);
  685.     FW_END_CONSTRUCTOR    
  686. }
  687.  
  688. //----------------------------------------------------------------------------------------
  689. //    CViewAsCommand destructor
  690. //----------------------------------------------------------------------------------------
  691.  
  692. CViewAsCommand::~CViewAsCommand()
  693. {
  694.     FW_START_DESTRUCTOR
  695.     
  696.     if (fOldViewAs)
  697.         FW_CMemoryManager::FreeBlock(fOldViewAs);
  698.     
  699.     delete fChangedContent;
  700.  
  701.     if (fUpdateShape)
  702.     {
  703.         FW_SOMEnvironment ev;
  704.         fUpdateShape->Release(ev);
  705.     }
  706.     fUpdateShape = NULL;
  707. }
  708.  
  709. //----------------------------------------------------------------------------------------
  710. //    CViewAsCommand::DoIt
  711. //----------------------------------------------------------------------------------------
  712.  
  713. void CViewAsCommand::DoIt(Environment* ev)    // Override
  714. {
  715.     // Copy selected proxy pointers to our content object
  716.     FW_ASSERT(fChangedContent == NULL);
  717.     fChangedContent = FW_NEW(CBaseContent, (ev, fContainerSelection->GetSelectionContent(ev)));
  718.  
  719.     fOldViewAs = (ODTypeToken*)FW_CMemoryManager::AllocateBlock(fContainerSelection->Count() * sizeof(ODTypeToken));
  720.     
  721.     short n = 0;
  722.     CContentProxyIterator it(fChangedContent);
  723.     for (CProxy* proxy = it.First(); it.IsNotComplete(); proxy = it.Next())
  724.     {
  725.         fOldViewAs[n] = proxy->GetViewAs();
  726.         n++;
  727.     }
  728.     
  729.     FW_ASSERT(fUpdateShape == NULL);
  730.     fUpdateShape = fChangedContent->CalcUpdateShape(ev);
  731.  
  732.     this->ChangeEmbeddedViewAs(ev, FALSE);
  733.  
  734.     {
  735.         FW_CAcquiredODShape tempShape = fChangedContent->CalcUpdateShape(ev);
  736.         fUpdateShape->Union(ev, tempShape);
  737.     }
  738.  
  739.     this->Redraw(ev);
  740. }
  741.  
  742. //----------------------------------------------------------------------------------------
  743. //    CViewAsCommand::UndoIt
  744. //----------------------------------------------------------------------------------------
  745.  
  746. void CViewAsCommand::UndoIt(Environment* ev)    // Override
  747. {
  748.     this->ChangeEmbeddedViewAs(ev, TRUE);
  749.     this->Redraw(ev);
  750. }
  751.  
  752. //----------------------------------------------------------------------------------------
  753. //    CViewAsCommand::RedoIt
  754. //----------------------------------------------------------------------------------------
  755.  
  756. void CViewAsCommand::RedoIt(Environment* ev)    // Override
  757. {
  758.     this->ChangeEmbeddedViewAs(ev, FALSE);
  759.     this->Redraw(ev);
  760. }
  761.  
  762. //----------------------------------------------------------------------------------------
  763. //    CViewAsCommand::ChangeEmbeddedViewAs
  764. //----------------------------------------------------------------------------------------
  765.  
  766. void CViewAsCommand::ChangeEmbeddedViewAs(Environment* ev, FW_Boolean undo)
  767. {
  768.     short n = 0;
  769.     //--- Resize each proxy ---
  770.     CContentProxyIterator it(fChangedContent);
  771.     for (CProxy* proxy = it.First(); it.IsNotComplete(); proxy = it.Next())
  772.     {
  773.         proxy->ChangeViewAs(ev, undo ? fOldViewAs[n] : fNewViewAs);
  774.         n++;
  775.     }
  776. }
  777.  
  778. //----------------------------------------------------------------------------------------
  779. //    CViewAsCommand::Redraw
  780. //----------------------------------------------------------------------------------------
  781.  
  782. void CViewAsCommand::Redraw(Environment* ev)
  783. {
  784.     FW_CPresentation* presentation = fContainerPart->GetMainPresentation();
  785.     presentation->Invalidate(ev, fUpdateShape);
  786.     
  787.     FW_CFacetClipper facetClipper;
  788.     facetClipper.Clip(ev, presentation, fUpdateShape);
  789.  
  790.     // Select the resized proxies
  791.     fContainerSelection->SelectContent(ev, fChangedContent);
  792. }
  793.  
  794. //========================================================================================
  795. // class CSetBackgroundColorCommand
  796. //========================================================================================
  797.  
  798. //----------------------------------------------------------------------------------------
  799. //    CSetBackgroundColorCommand::CSetBackgroundColorCommand
  800. //----------------------------------------------------------------------------------------
  801.  
  802. CSetBackgroundColorCommand::CSetBackgroundColorCommand(Environment* ev,
  803.                                                     CContainerPart* part,
  804.                                                     FW_CColor& newBackgroundColor) :
  805.     FW_CCommand(ev, cSetBackgroundColor, part->GetLastActiveFrame(ev), TRUE),
  806.     fContainerPart(part),
  807.     fOldColor(),
  808.     fNewColor(newBackgroundColor)
  809. {
  810.     fOldColor = fContainerPart->GetBackgroundColor();
  811.     SetMenuStringsFromResource(ev, kUndoStrings, kUndoSetBackColorMsg, kRedoSetBackColorMsg);
  812.     
  813.     FW_END_CONSTRUCTOR
  814. }
  815.  
  816. //----------------------------------------------------------------------------------------
  817. //    CSetBackgroundColorCommand::~CSetBackgroundColorCommand
  818. //----------------------------------------------------------------------------------------
  819.  
  820. CSetBackgroundColorCommand::~CSetBackgroundColorCommand()
  821. {
  822.     FW_START_DESTRUCTOR
  823. }
  824.  
  825. //----------------------------------------------------------------------------------------
  826. //    CSetBackgroundColorCommand::DoIt
  827. //----------------------------------------------------------------------------------------
  828.  
  829. void CSetBackgroundColorCommand::DoIt(Environment* ev)
  830. {
  831.     fContainerPart->SetBackgroundColor(ev, fNewColor);
  832. }
  833.  
  834. //----------------------------------------------------------------------------------------
  835. //    CSetBackgroundColorCommand::UndoIt
  836. //----------------------------------------------------------------------------------------
  837.  
  838. void CSetBackgroundColorCommand::UndoIt(Environment* ev)
  839. {
  840.     fContainerPart->SetBackgroundColor(ev, fOldColor);
  841. }
  842.  
  843. //----------------------------------------------------------------------------------------
  844. //    CSetBackgroundColorCommand::RedoIt
  845. //----------------------------------------------------------------------------------------
  846.  
  847. void CSetBackgroundColorCommand::RedoIt(Environment* ev)
  848. {
  849.     fContainerPart->SetBackgroundColor(ev, fNewColor);
  850. }
  851.